package com.itsu.app.controller;

import com.itsu.api.controllerApi.VideoControllerApi;
import com.itsu.app.service.AppVideoService;
import com.itsu.interfaces.service.VideoService;
import com.itsu.pojo.vo.PageResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class VideoController implements VideoControllerApi {

    @Autowired
    AppVideoService appVideoService;

    @Override
    public ResponseEntity publishVideo(MultipartFile videoThumbnail, MultipartFile videoFile) {
        appVideoService.saveVideo(videoThumbnail, videoFile);
        return ResponseEntity.ok(null);
    }

    @Override
    public ResponseEntity getVideos(Integer page, Integer pagesize) {
        PageResult pageResult = appVideoService.getVideos(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布小视频评论
     * @param id
     * @param comment
     * @return
     */
    @PostMapping("/{id}/comments")
    public ResponseEntity publishVideoComment(@PathVariable("id") String id, @RequestParam("comment") String comment) {
        appVideoService.publishVideoComment(id, comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频点赞
     * @param videoId
     * @return
     */
    @PostMapping("/{id}/like")
    public ResponseEntity likeVideo(@PathVariable("id") String videoId) {
        appVideoService.likeVideo(videoId);
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频取消点赞
     * @param videoId
     * @return
     */
    @PostMapping("/{id}/dislike")
    public ResponseEntity dislikeVideo(@PathVariable("id") String videoId) {
        appVideoService.dislikeVideo(videoId);
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频评论点赞
     * @param commentId
     * @return
     */
    @PostMapping("comments/{id}/like")
    public ResponseEntity likeVideoComments(@PathVariable("id") String commentId) {
        appVideoService.likeVideoComments(commentId);
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频评论取消点赞
     * @param commentId
     * @return
     */
    @PostMapping("comments/{id}/dislike")
    public ResponseEntity dislikeVideoComments(@PathVariable("id") String commentId) {
        appVideoService.dislikeVideoComments(commentId);
        return ResponseEntity.ok(null);
    }

    /**
     * 关注小视频发布者
     * @param uid
     * @return
     */
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") String uid) {
        appVideoService.userFocus(uid);
        return ResponseEntity.ok(null);
    }

    /**
     * 取消关注小视频发布者
     * @param uid
     * @return
     */
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") String uid) {
        appVideoService.userUnFocus(uid);
        return ResponseEntity.ok(null);
    }
}
